package com.comprehensive.personalfile.feign;

import com.comprehensive.common.dto.FolderFlieInfo;
import com.comprehensive.common.po.FileInfo;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@FeignClient(name = "personal-file-service")
public interface FileServiceFeignClient {

    @PostMapping(value = "/file/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    ResponseEntity<FileInfo> uploadFile(@RequestPart("file") MultipartFile file);

    @GetMapping("/file/download/{fileId}")
    ResponseEntity<byte[]> downloadFile(@PathVariable("fileId") String fileId);

    @GetMapping("/file/list")
    ResponseEntity<List<FolderFlieInfo>> listFiles(@RequestParam("directoryPath") String directoryPath);

    @GetMapping("/file/stream")
    ResponseEntity<byte[]> streamFile(@RequestParam("filePath") String filePath);

    @PostMapping(value = "/file/uploadChunk", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    ResponseEntity<FileInfo> uploadChunk(
            @RequestParam("uploadId") String uploadId,
            @RequestParam("chunkIndex") int chunkIndex,
            @RequestParam("totalChunks") int totalChunks,
            @RequestParam("fileName") String fileName,
            @RequestPart("chunkFile") MultipartFile chunkFile);

    @PostMapping("/file/mergeChunks")
    ResponseEntity<FileInfo> mergeChunks(
            @RequestParam("uploadId") String uploadId,
            @RequestParam("fileName") String fileName);

    @GetMapping("/file/uploadedChunks")
    ResponseEntity<List<Integer>> getUploadedChunks(
            @RequestParam("uploadId") String uploadId,
            @RequestParam("fileName") String fileName);

    @GetMapping("/file/markdown/content")
    ResponseEntity<String> getMarkdownContent(@RequestParam String filePath);
    @PostMapping("/file/markdown/save")
    ResponseEntity<Void> saveMarkdownContent(@RequestParam String filePath, @RequestBody String content);
}